# 将 path01 和 path02 中名字相同的进行改名，使其有序
#
import os
import glob
path01 = "images/"
path02 = "labels/"
imgs = glob.glob(path01+"/*g")
print(imgs)
labels = glob.glob(path02+"/*.txt")
print(labels)
ln = len(imgs)

def renameLabel(name, idx):
    for i in labels:
        newName = str(idx) + "." + i.split(".")[1]
        labelName = i.split("\\")[1].split(".")[0]
        if(labelName == name):
            dst_path = i.split("\\")[0]
            os.rename(i, dst_path + "/" + newName)

for idx, i in enumerate(imgs):
    idx+=115
    print(i, idx)
    idxi = "0000"+str(idx)
    fnameText = i.split("\\")[1].split(".")[0]
    newName = idxi +"."+i.split(".")[1]
    dst_path = i.split("\\")[0]
    os.rename(i, dst_path+"/"+newName)
    renameLabel(fnameText, idxi)


